home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10043 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  55 lines

  1. Path: brookes.ac.uk!news
  2. From: Krunchie <95155580@brookes.ac.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Kind of an annoying question...
  5. Date: 15 Mar 1996 04:07:00 GMT
  6. Organization: Digital Dynamics Unlimited
  7. Message-ID: <4iaqd4$l70@cs3.brookes.ac.uk>
  8. References: <4hvrio$c4k@lastactionhero.rs.itd.umich.edu>
  9. NNTP-Posting-Host: rm003a2e.brookes.ac.uk
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  14.  
  15. speng@stimpy.us.itd.umich.edu (Steve Palmer Peng) wrote:
  16. >I'm wondering, just what function in C allows me to enter a character
  17. >from the keyboard, and it automatically executes the command I designate
  18. >that character to.  For instance, I have something like,
  19. >
  20. >printf("Enter Y or N:");
  21. >
  22. >and I want the command after the printf statement to wait for input
  23. >from the keyboard, but once someone enters a Y or an N, the next line of
  24. >code is executed, without hitting enter.  Does anyone know how?  It would
  25. >be greatly appreciated if someone could help me out here...
  26. >
  27. >Steve
  28. >
  29. >
  30. Here is an example of how this can easily be achieved:
  31.  
  32. int main(void)
  33. {
  34. char choice;
  35. printf("Do you want to drop an H-Bomb on Iraq (Y or N)");
  36. choice=getch(); /* vital line */
  37. if(choice=='Y') start_war();
  38. /* rest of program */
  39. return 0;
  40. }
  41.  
  42. int start_war(void)
  43. {
  44. /* start war function */
  45. return 0;
  46. }
  47.  
  48.  
  49. Regards
  50.  
  51. Krunchie
  52. Digital Dynamics - Dynamic Software solutions for a dynamic world.
  53. 95155580@brookes.ac.uk
  54.  
  55.